package com.sgb.kjwl.view.ui.adapter.transport;


import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;

import com.sgb.kjwl.utils.NumberUtil;
import com.sgb.link.entity.AMapAddressEntity;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class AMapAddressAdapter extends BaseQuickAdapter<AMapAddressEntity, BaseViewHolder> {

    private int select = 0;

    public AMapAddressAdapter(@Nullable List<AMapAddressEntity> data) {
        super(R.layout.item_amap_adress, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, AMapAddressEntity item) {
        float distance = NumberUtil.convertToFloat(item.getDistance());
        holder.setText(R.id.tv_address, String.format("%s", item.getSnippet()))
                .setText(R.id.tv_distance, distance < 100 ? "100m内" : String.format("%sm", NumberUtil.trim0(distance)))
                .setText(R.id.tv_pro_city, String.format("%s%s%s",
                        item.getProvince(),
                        item.getCity(),
                        item.getDistrict()))
                .setVisible(R.id.iv_select, holder.getLayoutPosition() == select);
    }

    public int getSelect() {
        return select;
    }

    public void setSelect(int select) {
        this.select = select;
        notifyDataSetChanged();
    }

}
